package com.mgcoin.donguan.myuan;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import com.mgc.ar.lbsredpacket.activity.LBSAndPacketActivity;

import static com.mgcoin.donguan.myuan.R.layout.dialog;

public class MainActivity extends AppCompatActivity {

    private AlertDialog mDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void hello(View view) {
        Intent intent = new Intent(MainActivity.this, LBSAndPacketActivity.class);
        intent.putExtra("id", 1);
        startActivity(intent);
    }

    public void dialog(View view) {

        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setTitle("你号");
        builder.setMessage("我号");
        builder.setView(dialog);
        mDialog = builder.create();
        mDialog.show();
        //放在show()之后，不然有些属性是没有效果的，比如height和width
        Window dialogWindow = mDialog.getWindow();
        WindowManager m = getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        //设置高度和宽度
        //p.height = (int) (d.getHeight() * 0.4); // 高度设置为屏幕的0.6
        p.width = (int) (d.getWidth() * 0.6); // 宽度设置为屏幕的0.65
        dialogWindow.setAttributes(p);

    }

    public void dialogSure(View view) {
        mDialog.dismiss();
        Toast.makeText(MainActivity.this, "确定", Toast.LENGTH_SHORT).show();
    }
}
